<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.pyb.model.Student" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>学生列表 - 学生信息管理系统</title>
    <!-- 引入 Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .table-container {
            margin-top: 80px;
        }
        .table th, .table td {
            vertical-align: middle;
        }
        .actions a {
            margin-right: 10px;
            text-decoration: none;
        }
        .actions a:hover {
            text-decoration: underline;
        }
        .btn-back {
            margin-top: 20px;
        }
    </style>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">学生信息管理系统</a>
    </div>
</nav>

<div class="container table-container">
    <h2 class="mb-4 text-center">学生列表</h2>

    <%
        List<Student> students = (List<Student>) request.getAttribute("students");
        if (students == null || students.isEmpty()) {
    %>
    <div class="alert alert-info text-center" role="alert">
        暂无学生记录。
    </div>
    <%
    } else {
    %>
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover align-middle">
            <thead class="table-dark">
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>年龄</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                for (Student student : students) {
            %>
            <tr>
                <td><%= student.getId() %></td>
                <td><%= student.getName() %></td>
                <td><%= student.getAge() %></td>
                <td class="text-center actions">
                    <a href="student?action=edit&id=<%= student.getId() %>" class="text-primary">编辑</a>
                    <a href="student?action=delete&id=<%= student.getId() %>" class="text-danger" onclick="return confirm('确定要删除该学生吗？')">删除</a>
                </td>
            </tr>
            <%
                }
            %>
            </tbody>
        </table>
    </div>
    <%
        }
    %>

    <div class="text-center">
        <a href="index.jsp" class="btn btn-outline-secondary btn-back">返回首页</a>
    </div>
</div>

<!-- 引入 Bootstrap JS Bundle（包含 Popper） -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>